package netty.client;


import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ClientHandler extends SimpleChannelInboundHandler<String> {
    public static final Logger LOG = LoggerFactory.getLogger(ClientHandler.class);
    //for test
    long sum=0;
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        //print server ack
        //System.out.println("Server say : " + msg);
        //for test
        if(sum ==(Client.messageNum-1)){
            LOG.info("Server say : " + msg+Client.messageNum +", server had acks sum:"+sum+",start time is "+Client.sTime);
        }
        sum++;
    }
    /*
        *
        *when client setup,will invoke this channelActive
        * */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("Client active ");
        super.channelActive(ctx);
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("Client close ");
        super.channelInactive(ctx);
    }
}